package mo_gorm

import (
	"MoSkeleton/framework/core/config/properties_db"
	"MoSkeleton/framework/core/moerrors"
	"gorm.io/gorm"
)

// Sqlite数据库
type MoSqliteDb struct {
}

func (m *MoSqliteDb) GenDb(dbConfig *properties_db.GeneralDBProvider, testConn bool) (db *gorm.DB, err error) {
	dbProvider := *dbConfig
	if sqliteConfig, ok := dbProvider.(*properties_db.Sqlite); ok {
		return m.genSqliteByConfig(sqliteConfig, testConn)
	}
	return nil, moerrors.NewWithMsg("dbConfig is not sqlite")
}

func (m *MoSqliteDb) genSqliteByConfig(dbConfig *properties_db.Sqlite, testConn bool) (*gorm.DB, error) {
	//if dbConfig.Dbname == "" {
	//	return nil
	//}
	//
	//if db, err := gorm.Open(sqlite.New(dbConfig.Dsn()), gormConfig(dbConfig.GeneralDB, dbConfig.Prefix, dbConfig.Singular)); err != nil {
	//	panic(err)
	//} else {
	//	sqlDB, _ := db.DB()
	//	sqlDB.SetMaxIdleConns(dbConfig.MaxIdleConns)
	//	sqlDB.SetMaxOpenConns(dbConfig.MaxOpenConns)
	//	return db
	//}
	panic("uncomment up codes")
}
